<template>
  <div class="caseComp">
    <div class="caseCompTitle">编辑查实情况</div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否解决：" prop="status">
            <el-select
              v-model="ruleForm.status"
              width="100%"
              class="caseCompTitleInput"
            >
              <el-option
                v-for="item in resolveStatus"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="解决方式：" prop="solution">
            <el-select
              v-model="ruleForm.solution"
              width="100%"
              class="caseCompTitleInput"
            >
              <el-option
                v-for="item in resolveType"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="涉及人数：" prop="peopleCount">
            <el-input
              v-model="ruleForm.peopleCount"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="涉及金额：" prop="moneyTotal">
            <el-input
              v-model="ruleForm.moneyTotal"
              clearable=""
              placeholder="请输入"
              class="caseCompTitleInput"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="办结日期：" prop="overDate" width="100%">
            <el-date-picker
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              class="caseCompTitleInput"
              placeholder="选择日期"
              v-model="ruleForm.overDate"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div class="caseCompBtn">
      <el-button type="primary" class="commonBut saveBtn" @click="save"
        >保存</el-button
      >
      <el-button type="default" class="commonBut" @click="finish"
        >取消</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: 'caseDepartment',
  props: {
    childData: {
      type: Object,
      required: true,
      default() {
        return {}
      },
    },
  },
  data() {
    var checkMoney = (rule, value, callback) => {
      if (!value) {
        callback()
      } else {
        var rePayTotal =
          /^(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2})))$/
        if (!rePayTotal.test(value) || value == 0.0 || value == 0.0) {
          callback(new Error('金额格式不正确,必须大于0,最多带有2位小数'))
        } else {
          if (value >= 100000000000) {
            callback(new Error('金额需小于1000亿'))
          } else {
            callback()
          }
        }
      }
    }
    return {
      resolveStatus: [
        { value: '1', name: '已办结' },
        { value: '2', name: '办理中' },
        { value: '3', name: '待进一步办理' },
      ],
      resolveType: [
        { value: '1', name: '用人单位已支付' },
        { value: '2', name: '已劳动仲裁' },
        { value: '3', name: '人民法院诉讼' },
        { value: '4', name: '其他' },
      ],
      ruleForm: {
        id: '',
        status: '',
        solution: '',
        overDate: '',
        peopleCount: '',
        moneyTotal: '',
      },
      rules: {
        status: [
          { required: true, message: '请选择是否解决', trigger: 'change' },
        ],
        solution: [
          { required: true, message: '请选择解决方式', trigger: 'change' },
        ],
        peopleCount: [
          {
            pattern: /^[1-9]+[0-9]*$/,
            message: '请输入正整数',
            trigger: 'blur',
          },
        ],
        moneyTotal: [{ validator: checkMoney, trigger: 'blur' }],
      },
    }
  },
  mounted() {
    const { id, status, solution, overDate, peopleCount, moneyTotal } =
      this.childData
    this.ruleForm = { id, status, solution, overDate, peopleCount, moneyTotal }
    this.$refs.ruleForm.resetFields()
  },
  methods: {
    save() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.isLoading = true
          const { id, status, solution, overDate, peopleCount, moneyTotal } =
            this.ruleForm
          let params = {
            id,
            status,
            solution,
            overDate,
            peopleCount,
            moneyTotal,
          }
          this.axios
            .post('api-r/rbp/modifyRightsAppealComplaint', params)
            .then((res) => {
              if (!res.data.hasError) {
                this.$message({
                  type: 'success',
                  message: res.data.msg,
                })
                this.isLoading = false
                this.finish(1)
              } else {
                this.$message({
                  type: 'warning',
                  message: res.data.errorMsg,
                })
                this.isLoading = false
              }
            })
        } else {
          return false
        }
      })
    },
    finish(index) {
      this.$emit('callback', { success: index == 1 ? true : false })
    },
  },
}
</script>
<style lang="less" scoped>
.caseComp {
  border: 1px solid #dcdfe6;
  background-color: #f8f9fb;
  padding: 15px;
  &Title {
    color: #009588;
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 12px;
  }
  &List {
    line-height: 36px;
    height: 36px;
    font-size: 14px;
    color: #444;
    margin-bottom: 12px;
    &Title {
      display: inline-block;
      width: 85px;
      text-align: right;
    }
    &Input {
      width: calc(100% - 95px);
    }
    .input {
      width: calc(100% - 170px);
    }
  }
  &Btn {
    text-align: center;
    margin: 24px 0 10px;
    .el-button {
      width: 120px;
    }
  }
  /deep/ .el-radio__input.is-checked + .el-radio__label {
    color: #009588 !important;
  }
  /deep/.el-radio__input.is-checked .el-radio__inner {
    background: #009588 !important;
    border-color: #009588 !important;
  }
}
.caseCompTitleInput {
  width: calc(100% - 20px);
}
</style>
